package com.can.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.can.domain.ResponseResult;
import com.can.domain.entity.Tag;
import com.can.domain.vo.PageVO;
import com.can.domain.vo.TagListVO;
import com.can.mapper.TagMapper;
import com.can.service.TagService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * 标签(Tag) 服务实现类
 *
 * @author cancan
 * @since 2023-05-10 14:59:33
 */
@Service
public class TagServiceImpl extends ServiceImpl<TagMapper, Tag> implements TagService {
    @Override
    public ResponseResult<PageVO> pageTagList(Integer pageNum, Integer pageSize, TagListVO tagListVO) {
        //分页查询
        LambdaQueryWrapper<Tag> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.hasText(tagListVO.getName()),Tag::getName,tagListVO.getName());
        queryWrapper.like(StringUtils.hasText(tagListVO.getRemark()),Tag::getRemark,tagListVO.getRemark());

        Page<Tag> page = new Page<>();
        page.setCurrent(pageNum);
        page.setSize(pageSize);
        page(page, queryWrapper);
        //封装数据返回
        PageVO pageVO = new PageVO(page.getRecords(),page.getTotal());
        return ResponseResult.okResult(pageVO);
    }
}

